package com.baizhi.controller;

import com.baizhi.entity.Emp;
import com.baizhi.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/emp")
public class EmpController {

    private EmpService empService;

    @Autowired
    public EmpController(EmpService empService) {
        this.empService = empService;
    }

    // 查询所有
    @RequestMapping("findAll")
    public List<Emp> findAll() {
        return empService.findAll();
    }

    // 保存
    @PostMapping("save")
    public void save(@RequestBody Emp emp) {
        empService.save(emp);
    }

    // 根据id查询
    @GetMapping("{id}")
    public Emp findById(@PathVariable Integer id) {
        return empService.findById(id);
    }

    // 修改
    @PostMapping("edit")
    public void edit(@RequestBody Emp emp) {
        empService.edit(emp);
    }

    // 删除
    @DeleteMapping("{id}")
    public void delete(@PathVariable Integer id) {
        empService.delete(id);
    }

    // 查询所有 Map<id, name>
    @RequestMapping("findMap")
    public Map<Integer, String> findMap() {
        return empService.findMap();
    }
}
